(function injectFormatter() {
  try {
    // 按顺序加载文件：language-handlers.js -> vue-handler.js -> utils.js -> formatter.js
    const scripts = [
      'language-handlers.js',
      'vue-handler.js', 
      'utils.js',
      'formatter.js'
    ];
    
    let currentIndex = 0;
    
    function loadNextScript() {
      if (currentIndex >= scripts.length) {
        console.log('ConsoleFormatter: All scripts loaded successfully');
        return;
      }
      
      const scriptName = scripts[currentIndex];
      const script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = chrome.runtime.getURL(scriptName);
      
      script.onload = function () {
        console.log(`ConsoleFormatter: ${scriptName} loaded successfully`);
        currentIndex++;
        loadNextScript();
      };
      
      script.onerror = function () {
        console.error(`ConsoleFormatter: Failed to load ${scriptName}`);
        currentIndex++;
        loadNextScript();
      };
      
      (document.head || document.documentElement).appendChild(script);
    }
    
    loadNextScript();
  } catch (e) {
    console.error('ConsoleFormatter: Injection error:', e);
  }
})();


